<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>猜数字</title>
</head>
<body>
<input type="text" placeholder="请输入1-100的整数">
<input type="button" value="猜一猜" onclick="f()">
<h1>结果:<span></span></h1>
<script>
    // 获取一个1-100之间的整数
    let x = parseInt(Math.random()*100+1)
    // 获取文本框的内容
    let i = document.querySelector("input")
    let s = document.querySelector("span")
    function f(){
        if(i.value > x){
        s.innerText = "猜大了"
    }else if(i.value<x){
        s.innerText = "猜小了"
    }else {
        s.innerText = "恭喜你猜对了"
    }
    }
</script>
</body>
</html>